package com.love;

import java.util.Arrays;
import java.util.PriorityQueue;

public class MaxResource {



    public static int minMeetingRoom(int[][] ranges ){
        Arrays.sort(ranges,(a,b) -> a[0] - b[0]);

        PriorityQueue<Integer> pq = new PriorityQueue<>();

        int res = ranges[0][2];

        for (int i = 0; i < ranges.length; i++) {
            if(!pq.isEmpty()){
                Integer end = pq.poll();
                if(ranges[i][0] < end){
                    res += ranges[i][2];
                    pq.offer(end);
                }
            }
            pq.offer(ranges[i][1]);
        }
        return res;
    }


    public static void main(String[] args) {
        int[][] ranges = {
                {0,5,1},
                {2,4,1},
                {3,7,3},
                {6,9,2}
        };

        System.out.println(minMeetingRoom(ranges));
    }


}
